package com.example.myapplication;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

class StudentAdapter extends RecyclerView.Adapter<StudentViewHoder> {
    private ArrayList<Student>studentArrayList;

    public StudentAdapter(ArrayList<Student> studentArrayList) {
        this.studentArrayList = studentArrayList;
    }

    @NonNull
    @Override
    public StudentViewHoder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view= LayoutInflater.from(viewGroup.getContext()).inflate(
               R.layout.list_iteam,viewGroup,false);
        StudentViewHoder studentViewHoder=new StudentViewHoder(view);
        return studentViewHoder;
    }

    @Override
    public void onBindViewHolder(@NonNull StudentViewHoder studentViewHoder, int i) {
        Student student=studentArrayList.get(i);
        studentViewHoder.nameView.setText(student.getName());
        studentViewHoder.ageView.setText(String.valueOf(student.getAge()));
        Glide.with(studentViewHoder.iv_head.getContext())
                .load(student.getHeadIMG().getUrl()).into(studentViewHoder
        .iv_head);

    }

    @Override
    public int getItemCount() {
        return studentArrayList.size();
    }
}
